package org.korifey.ffbdd.samples.assign;

import java.util.HashSet;
import java.util.Set;

public class AssignBasic {
	Timetable timetable;
	Set<int[]> solves;
	
	public Set<int[]> solve(Timetable t) {
		timetable = t;
		
		solves = new HashSet<int[]>();
		int[] solve = new int[timetable.getSize()];
		
		inner(0, solve);
		return solves;
	}
	
	public void inner(int cnum, int[] solve) {
		if (cnum == timetable.getSize()) {
			solves.add(solve.clone());
			return;
		}
		cycle: for (Integer resnum: timetable.getConsumerResources(cnum)) {
			for (int i=0; i<cnum; i++) {
				if (resnum == solve[i]) continue cycle;
			}
			//int[] nsolve = solve.clone();
			solve[cnum] = resnum;
			inner(cnum+1, solve);
		}
	}
}
